package com.example.demothree.controller;

import com.example.demothree.bean.*;
import com.example.demothree.service.QueService;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@Controller
@RequestMapping("que")
public class QueController {
    @Resource
    private QueService queService;
    private Goods goods;
    private Suppliers suppliers;
    private Customer customer;
    private SaleItem saleItem;
    //商品查询
    @RequestMapping("quespcx")
    public String quespcx(Model model, HttpServletRequest request) throws IOException {
        String name = request.getParameter("spname");
        goods = queService.findByspName(name);
        model.addAttribute("goods",goods);
        return "quespcx";
    }
    //供应商查询
    @RequestMapping("quegyscx")
    public String quegyscx(Model model, HttpServletRequest request) {
        String name = request.getParameter("gysname");
        suppliers = queService.findgysByName(name);
        model.addAttribute("suppliers",suppliers);
        return "quegyscx";
    }
    @RequestMapping("quekhcx")
    public String quekhcx(Model model, HttpServletRequest request) {
        String name = request.getParameter("khname");
        customer = queService.findkhByName(name);
        model.addAttribute("customer",customer);
        return "quekhcx";
    }
    @RequestMapping("quexscx")
    public String quexscx(Model model, HttpServletRequest request) {
        String name = request.getParameter("xsname");
        saleItem = queService.findxsByName(name);
        model.addAttribute("saleItem",saleItem);
        return "quexscx";
    }
    @RequestMapping("quexstj")
    public String quexstj(HttpServletRequest req, HttpServletResponse res, Model model,//req接收前端数据，res向前端传输数据
                          @RequestParam(value = "page", defaultValue = "0") Integer page,
                          @RequestParam(value = "size", defaultValue = "5") Integer size) {
//        if (this.purId != 0L){//判断是否删除成功
//            Long deleteCgdd1 = this.purId;
//            model.addAttribute("deleteCgdd1",deleteCgdd1);
//        }
//        this.purId = 0L;
        //分页
            Page<SaleItem> pagexstj = queService.quexstj(page,size);
        model.addAttribute("pagexstj",pagexstj);
        return "quexstj";
    }
}
